home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / PROGTOOL / FLI106C.ZIP;1 / DIACOMBO.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-12  |  4.1 KB  |  182 lines

  1. //
  2. // The Fusion Library Interface for DOS
  3. // Version 1.06c
  4. // Copyright (C) 1990, 1991, 1992
  5. // Software Dimensions
  6. //
  7. // DialogClass
  8. // DiaCombo
  9. //
  10.  
  11. #include "fli.h"
  12. #include "elements.h"
  13. #include "colors.h"
  14.  
  15. #ifdef __BCPLUSPLUS__
  16. #pragma hdrstop
  17. #endif
  18.  
  19. #include <alloc.h>
  20. #include <ctype.h>
  21. #include <string.h>
  22. #include <dos.h>
  23.  
  24. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  25. //
  26. // DiaCombo()
  27. //
  28. // Constructor
  29. //
  30. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  31.  
  32. DiaCombo::DiaCombo(int _X,int _Y,int &NumberOfComboItems,char *_Mask,
  33.   char *_Value,int _VisualWidth,char MaskCharacter,int MaskWidth,
  34.   int _NoEditErase) :
  35.   DiaChar(_X,_Y,_Mask,_Value,_VisualWidth,MaskCharacter,MaskWidth,_NoEditErase),
  36.   ItemCount(NumberOfComboItems)
  37. {
  38.   DialogElement::Width++;
  39.   Item=0;
  40. }
  41.  
  42. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  43. //
  44. // Show()
  45. //
  46. // Show the character/combo element
  47. //
  48. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  49.  
  50. void DiaCombo::Show()
  51. {
  52.   DiaChar::Show();
  53.   (*Blaze) (X+DialogElement::Width-1,Y) <<
  54.     ((Available()==CompleteEvent)?Colors.DiaQuickKey:Colors.DiaDeadLocator) << '\x1f';
  55. }
  56.  
  57. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  58. //
  59. // HighLight()
  60. //
  61. // Highlight the combo/character element
  62. //
  63. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  64.  
  65. void DiaCombo::HighLight()
  66. {
  67.   DiaChar::HighLight();
  68. }
  69.  
  70. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  71. //
  72. // EventHandler()
  73. //
  74. // Handles the events
  75. //
  76. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  77.  
  78. // These classes are for the combo box drop down (it is a pick list)
  79.  
  80. class ComboPicker : public DiaPickGeneric
  81. {
  82. public:
  83.  
  84.   DiaCombo *Combo;
  85.  
  86.   ComboPicker(int Width,int Height,int &Item,int &NumberOfItems,
  87.     DiaCombo *ComboLocation) :
  88.     DiaPickGeneric(0,0,Width,Height,Item,NumberOfItems),
  89.     Combo(ComboLocation) { }
  90.  
  91.   char *GetItem(int);
  92. };
  93.  
  94. char *ComboPicker::GetItem(int Item)
  95. {
  96.   return Combo->GetItem(Item);
  97. }
  98.  
  99. class ComboHandler : public DialogClass
  100. {
  101. public:
  102.  
  103.   ComboHandler(int X,int Y,int Width,int Height) :
  104.     DialogClass(X,Y,Width,Height,"",0) { }
  105.  
  106.   int EventHandler(int);
  107.  
  108. };
  109.  
  110. int ComboHandler::EventHandler(int Event)
  111. {
  112.   if (Event==kbEsc ||
  113.       Event==kbCr ||
  114.       Event==OutsideEvent)
  115.     return StopEvent;
  116.   return CompleteEvent;
  117. }
  118.  
  119. // Here is the event handler for the DiaCombo element
  120.  
  121. int DiaCombo::EventHandler(int Event)
  122. {
  123.   if (Event==kbDown)
  124.   {
  125.     Item=(Item==ItemCount-1)?0:(++Item);
  126.     strcpy(Value,GetItem(Item));
  127.     CurrentLocation=0;
  128.     AtLeft=0;
  129.     HighLight();
  130.     return CompleteEvent;
  131.   }
  132.   else if (Event==kbUp)
  133.   {
  134.     Item=(!Item)?(ItemCount-1):(--Item);
  135.     strcpy(Value,GetItem(Item));
  136.     CurrentLocation=0;
  137.     AtLeft=0;
  138.     HighLight();
  139.     return CompleteEvent;
  140.   }
  141.   else if ((Event==ValidatedMousedEvent && MouseEvent==MouseLeftButtonRelease &&
  142.     MouseHorizontal==X+DialogElement::Width-1 && MouseVertical==Y) || Event==' ')
  143.   {
  144.     int X, Y, Width, Height;
  145.     int WinX=0, WinY=0, WinWidth=0, WinHeight=0;
  146.  
  147.     Blaze->WindowInformation(WinX,WinY,WinWidth,WinHeight);
  148.  
  149.     Width=DialogElement::Width+4;
  150.     Height=7;
  151.  
  152.     X=WinX+DialogElement::X;
  153.     Y=WinY+DialogElement::Y+1;
  154.  
  155.     if (X+Width>Blaze->WhatWidth())
  156.       X=Blaze->WhatWidth()-Width-1;
  157.  
  158.     if (Y+Height>Blaze->WhatHeight()-1)
  159.       Y=Blaze->WhatHeight()-Height-1;
  160.  
  161.     ComboHandler &Dialog = *new ComboHandler(X,Y,Width+2,Height);
  162.  
  163.     Dialog.Element(new ComboPicker(Width-3,Height-2,Item,ItemCount,this));
  164.     Dialog.Help("Select an item from the list box");
  165.  
  166.     int WhatLeft=Dialog.UseDialog();
  167.     delete &Dialog;
  168.  
  169.     if (WhatLeft==kbCr || MouseEvent&MouseDoubleClick)
  170.     {
  171.       strcpy(Value,GetItem(Item));
  172.       CurrentLocation=0;
  173.       AtLeft=0;
  174.       HighLight();
  175.     }
  176.  
  177.     return CompleteEvent;
  178.   }
  179.  
  180.   return DiaChar::EventHandler(Event);
  181. }
  182.